from PyQt5.QtWidgets import QWidget
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker


class BaseController(QWidget):
    """基础控制器类"""

    @staticmethod
    def get_sqlite3_connect(db_path, check_name_thread=False, echo=False):
        """创建 Sqlite3 数据库链接"""
        # 创建一个引擎
        engine = create_engine(f'sqlite:///{db_path}?check_name_thread={check_name_thread}', echo=echo)
        # 创建一个会话
        session = sessionmaker(bind=engine)
        db_session = session()
        return db_session

    @staticmethod
    def check_not_null(not_null):
        """
        检查非空
        :param not_null: 需要进行非空检测的所有变量
        :return: Bool
        """
        for item in not_null:
            if not item:
                return False
        return True

    def close_to(self, other):
        """关闭当前窗口到另一个窗口, 该窗口必须是在同级窗口中"""
        self.close()
        other.show()


class ProcessWindowController(BaseController):
    """主进程窗口控制类"""
    pass


class NoBorderController(BaseController):
    """无边框辅助控制器类"""

    def __init__(self):
        super().__init__()

    def close_action(self):
        """关闭窗口动作"""
        self.close()

    def min_action(self):
        """最小化窗口动作"""
        self.showMinimized()
